﻿using Kakaroto.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Kakaroto.Administracao.Relatorios
{
    public partial class Vendas : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Buscar_Click(object sender, EventArgs e)
        {
            VendasDS.SelectParameters[0].DefaultValue = txtInicio.Text;
            VendasDS.SelectParameters[1].DefaultValue = txtFim.Text;

            DateTime a = DateTime.Parse(txtInicio.Text);
            DateTime b = DateTime.Parse(txtFim.Text);

            KakarotoEntities _db = new KakarotoEntities();
            var totalRecebido = (from v in _db.Pedido
                                 where v.Entrada >= a && v.Entrada <= b
                                 group v by v.Status_Pagamento into t
                                 select new
                                 {
                                     status = t.Key,
                                     sum = t.Sum(soma => soma.Total)
                                 }).ToList();

            foreach (var x in totalRecebido)
            {
                if (x.status.Value == true)
                {
                    Recebido.Text = String.Format("{0:0.00}",x.sum.Value);
                }
                else
                {
                    Aberto.Text = String.Format("{0:0.00}", x.sum.Value);
                }  
            }
        }
    }
}